package com.editdialog.cn;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity implements InputEditDialog.OnTextSendListener {

    private TextView mContent;
    InputEditDialog mInputEditDialog;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mContent = findViewById(R.id.content);
        mInputEditDialog = new InputEditDialog(this, R.style.InputDialog, "");
        mInputEditDialog.setmOnTextSendListener(this);
        findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showInputMsgDialog();
            }
        });
    }

    /**
     * 弹出框
     */
    private void showInputMsgDialog() {
        WindowManager windowManager = getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = mInputEditDialog.getWindow().getAttributes();
        lp.width = (int) (display.getWidth()); //设置宽度
        mInputEditDialog.getWindow().setAttributes(lp);
        mInputEditDialog.setCancelable(true);
        mInputEditDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
        mInputEditDialog.show();
    }

    @Override
    public void onTextSend(String msg) {
        mContent.setText(msg);
    }
}
